<!DOCTYPE html>
<html>
<head>
    <title>内部邮件</title>
    <%include("/app/resapi/mobilestyle.html"){}%>
    <style type="text/css">
        .list-item {
            height: 100px;
        }
    </style>
</head>
<body>
<div align="left" style="width:100%;text-align: center">
    <a href="/mobile/email/index" class="btn btn-purple">邮件列表</a>
    <a href="/app/core/oa/email?view=msendemail" class="btn btn-default">编写邮件</a>
</div>
<div id="wrapper" style="margin-top: 40px;">
    <ul id="J_ListContent" class="m-list list-theme4"></ul>
    <div class="pull-loading">上拉加载</div>
</div>
<script id="J_ListHtml" type="text/html">
    {{each list as data}}
    <a href="/app/core/oa/emaildetails?emailId={{data.emailId}}" class="list-item">
        <div class="list-mes">
            <h3 class="list-title">{{data.subject}}</h3>
            <div class="list-mes-item" style="padding-right:20px;">
                    <span class="list-price" style="width:40%">
					发件人：{{data.fromUserName}}
					</span>
                <span class="list-price" style="width:60%">送达时间：{{data.sendTime}}</span>
            </div>
            <div class="list-mes-item" style="padding-right:20px;">
                {{data.subheading}}
            </div>
        </div>
    </a>
    {{/each}}
</script>
<%include("/app/resapi/mobilejs.html"){}%>
<script src="/module/art-template/template-web.js"></script>
<script>
    var dialog = YDUI.dialog;
    var num = 1;
    var page = 10; //每次加载10条
    $.ajax({
        url: "/mobile/mobileget/getMyEmailAllForMobile?page=1",
        type: "POST",
        dataType: 'json',
        success: function (res) {
            var data = res.list;
            if (data.length > 0) {
                $('#J_ListContent').append(template('J_ListHtml', {
                    list: data
                }));
                num = num + 1;
            }
            if (data.length == 0) {
                $('.pull-loading').html("我也有底线的~~");
            }
        }
    });

    var myscroll = new iScroll("wrapper", {
        onScrollMove: function () { //拉动时
            //上拉加载
            if (this.y < this.maxScrollY) {
                $(".pull-loading").html("释放加载");
                $(".pull-loading").addClass("loading");
            } else {
                $(".pull-loading").html("上拉加载");
                $(".pull-loading").removeClass("loading");
            }
        },
        onScrollEnd: function () { //拉动结束时
            //上拉加载
            if ($(".pull-loading").hasClass('loading')) {
                $(".pull-loading").html("加载中...");
                pullOnLoad();
            } else {
                //location.reload();
            }
        },
        onRefresh: function () {
            $('.pull-loading').html("上拉加载");
        }
    });

    function pullOnLoad() {
        setTimeout(function () {
            $.ajax({
                url: "/mobile/mobileget/getMyEmailAllForMobile?page=" + num,
                type: "POST",
                dataType: 'json',
                success: function (res) {
                    var data = res.list;
                    if (data.length > 0) {
                        $('#J_ListContent').append(template('J_ListHtml', {
                            list: data
                        }));
                        num = num + 1;
                        myscroll.refresh();
                    }
                    if (data.length == 0) {
                        $('.pull-loading').html("我也有底线的~~");
                        dialog.alert('已经到底了~~！');
                    }
                },
                error: function () {
                    console.log("出错了");
                }
            });
            myscroll.refresh();

        }, 1000);
    }
</script>
</body>
</html>
